package com.hits.zzbzstart.service;

import com.hits.zzbzstart.entity.TGzRmcs;
import com.hits.zzbzstart.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wangshen
 * @ClassName 使用地操作service
 * @Description TODO
 * @date 2020/12/22
 */
@Service
public class AreaService {

    @Autowired
    private RedisTemplate redisTemplate;

    public List<TGzRmcs> list() {
        try {
            BoundListOperations listOps = this.redisTemplate.boundListOps("areas");
            List<List<TGzRmcs>> list = listOps.range(0, listOps.size() - 1);
            List<TGzRmcs> tGzRmcs = list.get(0);
            tGzRmcs.forEach(e -> {
                String prefix = StringUtils.getAllFirstLetter(e.getDmjmc().substring(0, 1)).toUpperCase();
                e.setPrefix(prefix);
            });
            return tGzRmcs;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

}
